<template>
  <div class="app-container">
    <!-- 顶部查询 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="年度" prop="nd">
        <el-select filterable v-model="queryParams.nd" placeholder="请选择项目年度" clearable size="mini">
          <el-option
            v-for="dict in dict.type.year"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="文件名称" prop="wjName">
        <el-input
          size="mini"
          v-model="queryParams.wjName"
          placeholder="请输入文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批准文号" prop="pzWh">
        <el-input
          size="mini"
          v-model="queryParams.pzWh"
          placeholder="请输入批准文号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批准单位" prop="pzDw">
        <el-select filterable v-model="queryParams.pzDw" placeholder="请选择批准单位" clearable size="mini">
          <el-option
            v-for="dict in dict.type.xmgl_lxwj_pzdw"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="vxe-icon-file-excel"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lxwj:lxwj:export']"
        >导出Excel
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              v-loading="loading" :data="lxwjList" @selection-change="handleSelectionChange"
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" width="50"/>
      <el-table-column label="年度" align="center" prop="nd" width="120"/>
      <el-table-column label="文件名称" align="center" prop="wjName" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.wjName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="批准文号" align="center" prop="pzWh" show-overflow-tooltip width="180"/>
      <el-table-column label="批准单位" align="center" prop="pzDw" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xmgl_lxwj_pzdw" :value="scope.row.pzDw"/>
        </template>
      </el-table-column>
      <el-table-column label="填报人" align="center" prop="createBy" width="130"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 立项文件详情组件 -->
    <lx-wj-xq ref="lxWjXqPicture"></lx-wj-xq>

  </div>
</template>

<script>
import {
  addLxwj,
  delLxwj,
  getLxwj,
  getLxwjId,
  insertLxglLxwjFjByLxwjId,
  listLxwj,
  selectLxglLxwjFjList,
  selectLxwjLxxxByLxwjId,
  updateLxwj
} from "@/api/xmgl/lxgl/lxwj/lxwj";
import {getToken} from "@/utils/auth";
import KtXz from "@/views/components/ktXz/ktXz";
import LxWjXq from "@/views/xmgl/lxgl/xmcx/components/lxWjXq";
import Xmxq from "@/views/xmgl/lxgl/xmsb/components/xmxq";
import XmZe from "@/views/xmgl/lxgl/xmsb/components/xmZe";

export default {
  name: "index", //立项文件查询页面
  components: {XmZe, Xmxq, LxWjXq, KtXz},
  dicts: ['xmgl_lxwj_pzdw', 'kylx_ktgs', 'year'],
  data() {
    return {
      lxwjList: [],
      selectedRow: null, // 保存当前选中的行
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nd: null,
        wjName: null,
        pzWh: null,
        pzDw: null,
        userId: null,
        deptId: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;
      // 如果点击的行已经被选中，则取消选中
      if (selectedRows.includes(row)) {
        table.toggleRowSelection(row);
      } else {
        // 否则取消之前选中的行，并选中当前点击的行
        selectedRows.forEach(selectedRow => {
          table.toggleRowSelection(selectedRow);
        });
        table.toggleRowSelection(row);
      }
    },
    // 查询立项文件详情
    handleButtonClick(row) {
      this.$refs.lxWjXqPicture.handleOpen(row);
    },
    /** 查询立项文件列表 */
    getList() {
      this.loading = true;
      listLxwj(this.queryParams).then(response => {
        this.lxwjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.lxwjId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lxwj/lxwj/export', {
        ...this.queryParams
      }, `lxwj_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>

<style scoped>
/* header 头部背景 */
/deep/ .el-card__header {
  padding: 3px 7px 3px;
  min-height: 10px;
  background-color: aliceblue;
}
</style>
